package top.kaoshanji.ch05;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import top.kaoshanji.ch05.equals.Employee;
import top.kaoshanji.ch05.equals.Manager;

/**
 * 代码清单 ch05-02：Object类的方法
 * @see top.kaoshanji.ch05.equals.Employee
 * @see top.kaoshanji.ch05.equals.Manager
 * author kaoshanji
 * ^_^
 * create time 2024/11/25 21:58
 */
public class EqualsTest {

    private static final Logger logger = LogManager.getLogger(EqualsTest.class);

    public static void main(String[] args) {
        logger.info("...代码清单 ch05-02：Object类的方法...");

        var alice1 = new Employee("Alice Adams", 75000, 1987, 12, 15);
        var alice2 = alice1;
        var alice3 = new Employee("Alice Adams", 75000, 1987, 12, 15);
        var bob = new Employee("Bob Brandson", 50000, 1989, 10, 1);

        System.out.println("alice1 == alice2: " + (alice1 == alice2));

        System.out.println("alice1 == alice3: " + (alice1 == alice3));

        System.out.println("alice1.equals(alice3): " + alice1.equals(alice3));

        System.out.println("alice1.equals(bob): " + alice1.equals(bob));

        System.out.println("bob.toString(): " + bob);

        var carl = new Manager("Carl Cracker", 80000, 1987, 12, 15);
        var boss = new Manager("Carl Cracker", 80000, 1987, 12, 15);
        boss.setBonus(5000);
        System.out.println("boss.toString(): " + boss);
        System.out.println("carl.equals(boss): " + carl.equals(boss));
        System.out.println("alice1.hashCode(): " + alice1.hashCode());
        System.out.println("alice3.hashCode(): " + alice3.hashCode());
        System.out.println("bob.hashCode(): " + bob.hashCode());
        System.out.println("carl.hashCode(): " + carl.hashCode());

    }

}
